home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '90 / Other Stuff / Networking ƒ / ATP Sample App / packets / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-02  |  2.6 KB  |  170 lines  |  [TEXT/KAHL]

  1. #include "packets.h"
  2.  
  3. main()
  4. {
  5.     SetupMac();
  6.     SetupMenu();
  7.     
  8.     InitThem();
  9.  
  10.     while ( DoLoop() );
  11. }
  12.  
  13. SetupMac()
  14. {
  15.     InitGraf(&thePort);
  16.     InitFonts();
  17.     InitWindows();
  18.     InitDialogs(0L);
  19.     InitMenus();
  20.     TEInit();
  21.     FlushEvents(everyEvent, 0);
  22.     HiliteMenu(0);
  23.  
  24.     Stdio_MacInit(TRUE);
  25.     printf("Packet Blaster Test v0.5\n");
  26.  
  27.     Click_On(FALSE);
  28. }
  29.  
  30. MenuHandle myMenus[3];
  31.  
  32. #define    appleID        1
  33. #define    testID        128
  34.  
  35. SetupMenu()
  36. {
  37.     if (GetResource('MENU', testID)==0) {
  38.         SysBeep(20);
  39.         return;
  40.     }
  41.     
  42.     myMenus[0] = NewMenu( appleID, "\p\024" );
  43.     AppendMenu(myMenus[0], "\pAbout this program...;(-");
  44.     
  45.     AddResMenu( myMenus[0], 'DRVR' );
  46.     InsertMenu(myMenus[0], 0) ;
  47.  
  48.     myMenus[1] = GetMenu(testID);
  49.     InsertMenu(myMenus[1], 0) ;
  50.  
  51.     DrawMenuBar();
  52. }
  53.  
  54. int DoCommand( mResult )
  55. long mResult;
  56. {
  57.     int        theItem, temp;
  58.     Str255    name;
  59.     GrafPtr port;
  60.     
  61.     theItem = LoWord( mResult );
  62.     switch (HiWord(mResult)) {
  63.  
  64.     case appleID:
  65.         GetPort( &port );
  66.         if (theItem == 1)
  67.             DoAbout();
  68.         else
  69.             {
  70.             GetItem(myMenus[0], theItem, &name);
  71.             OpenDeskAcc( &name );
  72.             }
  73.         SetPort( port );
  74.         break;
  75.  
  76.     case testID: 
  77.         switch (theItem)
  78.             {
  79.             case 1:
  80.                 Configure();
  81.                 break;
  82.             case 2:
  83.                 SendThem();
  84.                 break;
  85.             case 3:
  86.                 ReceiveThem();
  87.                 break;
  88.             case 5:
  89.                 HiliteMenu(0);
  90.                 return 0;
  91.                 break;
  92.             }
  93.         break;
  94.     }
  95.  
  96.     HiliteMenu(0);
  97.     return(1);
  98. }
  99.  
  100.  
  101. DoLoop()
  102. {
  103.     int    where;
  104.     EventRecord        myEvent;
  105.     WindowPtr        whichWindow;
  106.     
  107.     SystemTask();
  108.  
  109.     if (GetNextEvent(everyEvent, &myEvent))
  110.         {
  111.         if ( !StdEvent( &myEvent ) )
  112.             if (myEvent.what == mouseDown)
  113.                 {
  114.                 if ( where = FindWindow( myEvent.where, &whichWindow ) )
  115.                     {
  116.                     if (where == inMenuBar)
  117.                         return( DoCommand( MenuSelect(myEvent.where) ) );
  118.  
  119.                     if (where == inSysWindow)
  120.                         SystemClick( &myEvent, whichWindow );
  121.                     }
  122.                 }
  123.             else
  124.                 if (myEvent.what == keyDown)
  125.                     {
  126.                     register char    theChar;
  127.                     
  128.                     theChar = myEvent.message & charCodeMask;
  129.                     if ((myEvent.modifiers & cmdKey) != 0) 
  130.                         return( DoCommand( MenuKey( theChar ) ));
  131.                     }
  132.         }
  133.  
  134.     return(1);
  135. }
  136.  
  137. DoAbout()
  138. {
  139.     WindowPtr w;
  140.     Rect    windRect;
  141.     char    version[40];
  142.  
  143.     /* make log window rect bottom */
  144.     SetRect(&windRect, 50, 50, 410, 145);
  145.     
  146.     /* create log window */
  147.     w = NewWindow( 0L, &windRect, "\pAbout Packets...", TRUE,
  148.                           altDBoxProc, (WindowPtr)-1, TRUE, 0L );
  149.     SetPort(w);
  150.     
  151.     TextFont(monaco);
  152.     TextSize(9);
  153.  
  154.     sprintf(version, "Packets v0.5");
  155.     CtoPstr(version);
  156.     
  157.     MoveTo(2, 10);
  158.     DrawString(version);
  159.     MoveTo(2, 20);
  160.     DrawString("\pBrad Parker (brad@cayman.com)");
  161.  
  162.     MoveTo(2, 40);
  163.     DrawString("\pDesiged to test packet throughput of appletalk");
  164.     MoveTo(2, 55);
  165.     DrawString("\prouters.");
  166.  
  167.     while (!Button());
  168.     
  169.     DisposeWindow(w);
  170. }